package ArrayList;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentDemo2 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList();
        addStudent(list);
        addStudent(list);
        addStudent(list);

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

    }
    public static void addStudent(ArrayList list){
        Scanner sc = new Scanner(System.in);
        System.out.println("学生的姓名是:");
        String name = sc.next();
        System.out.println("学生的年龄是:");
        int age = sc.nextInt();
        System.out.println("学生的性别为:");
        String sex = sc.next();

        Student stu1 = new Student(name,age,sex);
        list.add(stu1);
    }
}
